package com.mr.security.web.commons.validate.smscode;

import com.mr.security.web.commons.config.SecurityPropertiesConfig;
import com.mr.security.web.commons.validate.IValidateCodeGenerator;
import com.mr.security.web.commons.validate.entity.ValidateCode;
import lombok.Data;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * Class: ImageCodeGeneratorImpl
 * User (作者):MRui
 * TODO (描述)：图形验证码生成器实现
 * Date 2019-01-22 23:28
 */
@Data
@Component("smsIValidateCodeGenerator")
public class SmsValidateCodeGeneratorImpl implements IValidateCodeGenerator {

    /** security属性配置类 */
    @Autowired
    private SecurityPropertiesConfig securityProperties;

    /**
    * User (作者): MRui
    * TODO (描述)：验证码实现方法
    * Data：2019-01-22 23:29
    */
    @Override
    public ValidateCode generateCode(ServletWebRequest request) {
        String code = RandomStringUtils.randomNumeric(securityProperties.getSmsCodeLength());
        return new ValidateCode(code,securityProperties.getSmsCodeExpireIn());
    }
}
